.\" .\" UCSD p-System cross compiler .\" Copyright (C) 2011, 2012 Peter Miller .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or (at .\" you option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU .\" General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License along .\" with this program. If not, see .\" .nf .ad l .hy 0 Miller, P. A. (2010) Factory Factory Factories
Up, Prev Next

What's in a Name?

...imperative type-based dispatch ... facility of the C++ language
expression
    : NAME
        { $$ = context->name_expression($1); }
    | etc etc etc
    ;
class symbol
{
public:
    virtual expression *name_expression_factory(const char *name);
};
expression *
translator_compiler::name_expr_factory(const char *name) {
    symbol *sp = lookup(name);
    if (!sp) {
        yyerror("name \"%s\" unknown", name);
        return new expr_error();
    }
expression *
translator::name_expr_factory(const char *name) {
    symbol *sp = lookup(name);
    if (!sp) {
        yyerror("name \"%s\" unknown", name);
        return new expr_error();
    }
 
    return sp->name_expression_factory() const;
}
    const symbol_global *test1 =
        dynamic_cast<const symbol_global *>(sp);
    if (test1)
        return new expression_ldo(sp->get_address());
expression *
symbol_global::name_expression_factory()
    const
{
    return new expression_ldo(get_address());
}
    yyerror("can't use name \e"%s\e" here", sp->get_name());
    return new expression_error();
}
expression *
symbol::name_expression_factory()
{
    yyerror("can't use name \e"%s\e" here", get_name());
    return new expression_error();
}
Now we have a factory factory factory.
.\" vim: set ts=8 sw=4 et :